package code.android.MiracleWalker.overlay;

import java.util.List;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.location.Location;

import code.android.MiracleWalker.activity.MwMapActivity;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class TrakingDrawOverlay extends Overlay {
	Paint mPaint = null;
	List<String> mLocationList = null;
	Point mBeforePoint = null;
	Point mAfterPoint = null;
	
	public TrakingDrawOverlay(List<String> locationList) {
		mLocationList = locationList;
		mPaint = new Paint();
		mPaint.setAntiAlias(true);
		mPaint.setColor(Color.RED);
		mPaint.setStyle(Paint.Style.FILL);
		mPaint.setStrokeWidth(4);

		mBeforePoint = new Point();
		mAfterPoint = new Point();
	}
	
	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow)
	{
		if(mLocationList.isEmpty() == false && mLocationList.size() > 1)
		{
			for(int i = mLocationList.size()-1; i > 0; i-- ) 
			{
				Projection projection = mapView.getProjection();
				
				String[] string = mLocationList.get(i).split(";");
							
				int latitude1 = Integer.parseInt(string[1]);
				int longitude1 = Integer.parseInt(string[2]);
				
				string = mLocationList.get(i-1).split(";");
				
				int latitude2 = Integer.parseInt(string[1]);
				int longitude2 = Integer.parseInt(string[2]);
				
				projection.toPixels(new GeoPoint(latitude1, longitude1), mBeforePoint);
				projection.toPixels(new GeoPoint(latitude2, longitude2), mAfterPoint);
				
				canvas.drawLine(mBeforePoint.x, mBeforePoint.y, mAfterPoint.x, mAfterPoint.y, mPaint);
			}
		}

		super.draw(canvas, mapView, shadow);
	}

}
